package org.zhouhe.interceptor;

import java.util.Map;

import org.zhouhe.util.Constant;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 权限拦截器 ：检查用户是否有执行“某Action中某方法”的权限。<br>
 * 注意：本拦截器只能限制Struts2的Action中的方法，无法权限jsp、html、js、jpg等其它类型的方法
 * 
 * @author 周鹤
 */
@SuppressWarnings( { "serial" })
public class AuthorityInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map<String, Object> session = invocation.getInvocationContext().getSession();
	/*	String path = invocation.getAction().getClass().getName();
		String method = invocation.getProxy().getMethod();
		List<String> authorityList = (List<String>) session.get(Constant.SESSION_KEY_USER_METHOD_LIST);
		if (authorityList != null && authorityList.contains(path + "." + method)) {
			return invocation.invoke();
		}*/
		if (session.get(Constant.SESSION_KEY_USER_INFO) != null) {
			return invocation.invoke();
		}else{
		}
		return Action.LOGIN;
	}

}
